<template>
	<view>
		<view class="goods_cate">

			<view class="left_scroll" scroll-x="true">
				<view v-for="(item,index) in left_scoll" :key="index" class="left_title"
					:class="index == indexValue ? 'left_color': ''" @click="ClickIndex(index,item.id)">
					{{item.cateName}}
				</view>
			</view>
			<!-- <view class="tabSearch">
				<view class="pr">
					<view class="Search">
						<view class="margin-horizontal-main padding-horizontal-main bg-white">
							<component-search propPlaceholder="输入商品名称搜索" propBgColor="#f9f9f9"></component-search>
						</view>
					</view>
				</view>
			</view> -->
			<view class="Cate">
				<scroll-view class="right_scroll" scroll-y="true">
					<view class="right_goods_info" v-for="(item,index) in rightList" :key="index"
						@click="Navgetto(item)">
						<view class="right_goods_image">
							<image :src="util.imageApi+item.image"></image>
						</view>
						<view class="right_goods_info_title">
							<view class="storeName">
								{{item.storeName}}
							</view>
							<view class="public">
								<view class="price">
									￥<span>{{item.price}}</span>
								</view>
								<!-- <view class="sell">
									已售{{item.sales}}
								</view> -->
							</view>
						</view>
						<view class="right_goods_info_right" v-if="fuck">
							<image src="../../static/3x/add.png" mode="" @click.stop="handleAddShopping(item)"
								v-if="numb"></image>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	import componentSearch from "../../components/search/search.vue";
	import util from "@/util/index.js"
	export default {
		components: {
			componentSearch
		},
		data() {
			return {
				util: util,
				left_scoll: [],
				indexValue: 1,
				rightList: [],
				id: '',
				fuck: false,
				numb: true,
				flag: true,
			}
		},
		onPullDownRefresh() {
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		methods: {
			handleAddShopping(item) {
				this.$http({
					url: '/crmStoreCart/insCrmStoreCart',
					data: {
						productId: item.id,
						cartNum: 1,

					},
				}).then(res => {
					if (res.data.code === 200) {
						uni.showToast({
							title: "添加成功",
							icon: "none"
						}).then(this.Shopshow = false)
					}
				})
			},
			Navgetto(item) {
				if (item.isCashoutProduct == 1) {
					uni.navigateTo({
						url: '/pages/withdrawal/withdrawal?id=' + item.id
					})
				} else if (item.storeName == "寄售100枚鸡蛋") {
					uni.navigateTo({
						url: '/pages/jishoujidan/jishoujidan'
					})
				} else {
					uni.navigateTo({
						url: '../goods-detail/goods-detail?id=' + item.id
					})
				}

			},
			GetSearch() {
				this.$http({
					url: '/crmStoreCategory/selCrmStoreCategory',
					method: 'POST'
				}).then(res => {
					if (this.flag) {
						this.left_scoll = res.data.data
					} else {
						this.left_scoll = res.data.data.slice(0, -1)
					}
				})
			},
			ClickIndex(index, id) {
				this.fuck = false
				this.indexValue = index
				this.id = id
				if (this.id == 2 || this.id == 3) {
					this.fuck = true
				}
				this.$http({
					url: '/crmStoreProduct/selCrmStoreProductClassification',
					method: 'GET',
					data: {
						CateId: id
					}
				}).then(res => {
					this.rightList = res.data.data.list
				})
			},
		},
		onLoad() {
			this.$http({
				url: "/member/getMyPage"
			}).then(res => {
				this.flag = res.data.data.flag
				if (res.data.data.chickenNum < 20) {
					this.numb = false
				}
			})
			setTimeout(() => {
				this.GetSearch()
				this.ClickIndex(0, 1)
			}, 100)
		},

	}
</script>

<style lang="scss" scoped>
	@import './goods-category.css';
</style>
